package com.niuwa.p2p.service.impl.business;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.dao.business.InvestDao;
import com.niuwa.p2p.dao.customer.CustomerDao;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.p2p.service.business.IInvestService;
import com.niuwa.p2p.vo.business.InvestRecordVo;

@Service
public class InvestServiceImpl implements IInvestService {

	@Autowired
	private InvestDao investDao;
	
	@Autowired
	private CustomerDao customerDao;
	
	@Override
	public BigDecimal getToAssignAmout() {
		return investDao.selectToAssignAmout();
	}

	@Override
	public PageBean<InvestRecordVo> selectInvestRecordList(
			Map<String, Object> paramMap) throws Exception {
		
		assert paramMap.get(PageQuery.PAGEQUERY) != null;

		int totalCount = investDao.count(paramMap);

		PageBean<InvestRecordVo> page = new PageBean<InvestRecordVo>(totalCount);

		page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY)).getPage());
		
		List<InvestRecordVo> investList = investDao.selectInvestRecordList(paramMap);
		
		for (InvestRecordVo investRecordVo : investList) {
			if(String.valueOf(investRecordVo.getCustId()) != null){
				investRecordVo.setCustName(customerDao.selectByCustId(investRecordVo.getCustId()).getLoginName());
			}
		}

		page.setRows(investList);
		
		return page;
	}

}
